from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-07 14:02:26.785184
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 07, Jan, 2023
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3577
Nobs: 894.000 HQIC: -51.6560
Log likelihood: 11845.9 FPE: 3.06176e-23
AIC: -51.8405 Det(Omega_mle): 2.77009e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290614 0.048976 5.934 0.000
L1.Burgenland 0.107901 0.033757 3.196 0.001
L1.Kärnten -0.106105 0.018115 -5.857 0.000
L1.Niederösterreich 0.215652 0.070834 3.044 0.002
L1.Oberösterreich 0.077686 0.066910 1.161 0.246
L1.Salzburg 0.249646 0.035877 6.958 0.000
L1.Steiermark 0.032126 0.047043 0.683 0.495
L1.Tirol 0.124785 0.038169 3.269 0.001
L1.Vorarlberg -0.058856 0.032882 -1.790 0.073
L1.Wien 0.070379 0.059675 1.179 0.238
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059682 0.100298 0.595 0.552
L1.Burgenland -0.009122 0.069131 -0.132 0.895
L1.Kärnten 0.048882 0.037098 1.318 0.188
L1.Niederösterreich -0.170256 0.145060 -1.174 0.241
L1.Oberösterreich 0.359910 0.137024 2.627 0.009
L1.Salzburg 0.285850 0.073471 3.891 0.000
L1.Steiermark 0.107295 0.096338 1.114 0.265
L1.Tirol 0.319869 0.078165 4.092 0.000
L1.Vorarlberg 0.025582 0.067339 0.380 0.704
L1.Wien -0.022000 0.122208 -0.180 0.857
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197900 0.025638 7.719 0.000
L1.Burgenland 0.092201 0.017671 5.218 0.000
L1.Kärnten -0.008597 0.009483 -0.907 0.365
L1.Niederösterreich 0.267866 0.037080 7.224 0.000
L1.Oberösterreich 0.108774 0.035026 3.106 0.002
L1.Salzburg 0.053485 0.018780 2.848 0.004
L1.Steiermark 0.016658 0.024626 0.676 0.499
L1.Tirol 0.099235 0.019980 4.967 0.000
L1.Vorarlberg 0.058405 0.017213 3.393 0.001
L1.Wien 0.114827 0.031238 3.676 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105149 0.026224 4.010 0.000
L1.Burgenland 0.049189 0.018075 2.721 0.007
L1.Kärnten -0.015769 0.009700 -1.626 0.104
L1.Niederösterreich 0.198126 0.037928 5.224 0.000
L1.Oberösterreich 0.274829 0.035826 7.671 0.000
L1.Salzburg 0.117490 0.019210 6.116 0.000
L1.Steiermark 0.101414 0.025189 4.026 0.000
L1.Tirol 0.122472 0.020437 5.993 0.000
L1.Vorarlberg 0.071098 0.017607 4.038 0.000
L1.Wien -0.024919 0.031953 -0.780 0.435
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132055 0.047013 2.809 0.005
L1.Burgenland -0.052241 0.032404 -1.612 0.107
L1.Kärnten -0.035486 0.017389 -2.041 0.041
L1.Niederösterreich 0.167083 0.067995 2.457 0.014
L1.Oberösterreich 0.128897 0.064228 2.007 0.045
L1.Salzburg 0.290095 0.034438 8.424 0.000
L1.Steiermark 0.035435 0.045157 0.785 0.433
L1.Tirol 0.156622 0.036639 4.275 0.000
L1.Vorarlberg 0.110002 0.031564 3.485 0.000
L1.Wien 0.068984 0.057283 1.204 0.228
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061892 0.037466 1.652 0.099
L1.Burgenland 0.039430 0.025824 1.527 0.127
L1.Kärnten 0.049830 0.013858 3.596 0.000
L1.Niederösterreich 0.226775 0.054187 4.185 0.000
L1.Oberösterreich 0.263948 0.051185 5.157 0.000
L1.Salzburg 0.060062 0.027445 2.188 0.029
L1.Steiermark -0.005785 0.035987 -0.161 0.872
L1.Tirol 0.156960 0.029198 5.376 0.000
L1.Vorarlberg 0.069383 0.025155 2.758 0.006
L1.Wien 0.078056 0.045651 1.710 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191100 0.045179 4.230 0.000
L1.Burgenland 0.018580 0.031140 0.597 0.551
L1.Kärnten -0.057024 0.016711 -3.412 0.001
L1.Niederösterreich -0.095515 0.065343 -1.462 0.144
L1.Oberösterreich 0.175632 0.061723 2.846 0.004
L1.Salzburg 0.061205 0.033095 1.849 0.064
L1.Steiermark 0.225008 0.043396 5.185 0.000
L1.Tirol 0.477256 0.035210 13.555 0.000
L1.Vorarlberg 0.053255 0.030333 1.756 0.079
L1.Wien -0.047880 0.055049 -0.870 0.384
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149501 0.050781 2.944 0.003
L1.Burgenland 0.000748 0.035001 0.021 0.983
L1.Kärnten 0.067462 0.018782 3.592 0.000
L1.Niederösterreich 0.202950 0.073444 2.763 0.006
L1.Oberösterreich -0.070729 0.069375 -1.020 0.308
L1.Salzburg 0.220754 0.037198 5.935 0.000
L1.Steiermark 0.108837 0.048776 2.231 0.026
L1.Tirol 0.081348 0.039575 2.056 0.040
L1.Vorarlberg 0.128609 0.034094 3.772 0.000
L1.Wien 0.111515 0.061874 1.802 0.072
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353218 0.030161 11.711 0.000
L1.Burgenland 0.010001 0.020788 0.481 0.630
L1.Kärnten -0.024863 0.011156 -2.229 0.026
L1.Niederösterreich 0.230857 0.043622 5.292 0.000
L1.Oberösterreich 0.148086 0.041205 3.594 0.000
L1.Salzburg 0.052434 0.022094 2.373 0.018
L1.Steiermark -0.015594 0.028970 -0.538 0.590
L1.Tirol 0.118984 0.023505 5.062 0.000
L1.Vorarlberg 0.074645 0.020250 3.686 0.000
L1.Wien 0.053400 0.036750 1.453 0.146
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039879 0.170303 0.187563 0.173364 0.151718 0.133856 0.071971 0.225457
Kärnten 0.039879 1.000000 0.004502 0.132680 0.027781 0.099967 0.427995 -0.047384 0.102544
Niederösterreich 0.170303 0.004502 1.000000 0.358366 0.178928 0.326361 0.145723 0.200811 0.350854
Oberösterreich 0.187563 0.132680 0.358366 1.000000 0.242260 0.350795 0.194786 0.185813 0.280735
Salzburg 0.173364 0.027781 0.178928 0.242260 1.000000 0.161106 0.146720 0.156728 0.146282
Steiermark 0.151718 0.099967 0.326361 0.350795 0.161106 1.000000 0.172462 0.154478 0.106008
Tirol 0.133856 0.427995 0.145723 0.194786 0.146720 0.172462 1.000000 0.130988 0.172627
Vorarlberg 0.071971 -0.047384 0.200811 0.185813 0.156728 0.154478 0.130988 1.000000 0.028151
Wien 0.225457 0.102544 0.350854 0.280735 0.146282 0.106008 0.172627 0.028151 1.000000